﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
using JY.Wpf.Core.Enums;

namespace JY.Wpf.Controls.Converters
{
    /// <summary>
    /// 消息类型转颜色转换器
    /// </summary>
    public class MessageTypeToColorConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            MessageType messageType = MessageType.Success;

            if (value != null)
            {
                Enum.TryParse(value.ToString(), out messageType);
            }
            string brush = "";
            switch (messageType)
            {
                case MessageType.Success:
                case MessageType.Info:
                case MessageType.Warning:
                    brush = messageType.ToString();
                    break;
                case MessageType.Error:
                    brush = "Danger";
                    break;
                case MessageType.Ask:
                    brush = "Accent";
                    break;
                case MessageType.Fatal:
                    brush = "PrimaryText";
                    break;
            }
            return Application.Current.Resources[$"{brush}Brush"];
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
